import { defineStore } from "pinia";
import { AddressList } from "vant";

export const userStore = defineStore('user',{
    state:()=>({  //数据
        addressList:[
            {
            id: 1,
            name: '张三',
            tel: '13800138000',
            address: '北京市朝阳区建国路100号',
            isDefault: true
          },
          {
            id: 2,
            name: '李四',
            tel: '13900139000',
            address: '上海市浦东新区陆家嘴环路200号',
            isDefault: false
          }],
          disabledList:[
            {
                id: '3',
                name: '王五',
                tel: '1320000000',
                address: '浙江省杭州市滨江区江南大道 15 号',
            }
          ]
    }),
    actions:{    //方法
      //增加地址
      addAddress(content){
        this.addressList.map((item) => {
          if (content.isDefault) {
            item.isDefault = false;
          }
        });
        this.addressList.push(content)
      },
      //编辑地址
      editAddress(content){
        this.addressList = this.addressList.map((item)=>{
          if(content.isDefault){
            item.isDefault = false;
          }
          return item.id == content.id ? content : item
          
        })
      }

    },
    getters:{  //获取值
        
    }
})